package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.po.InteractionQuestion;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import groovy.util.logging.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author zhongweiwei
 * @since 2023-05-29
 */
@Slf4j
@RestController
@Api(value = "问题相关", tags = "问题相关接口")
@RequiredArgsConstructor
@RequestMapping("/questions")
public class InteractionQuestionController {
    private final IInteractionQuestionService interactionQuestionService;

    @PostMapping()
    @ApiOperation("新增互动问题")
    public void addInteractionQuestion(@Valid @RequestBody QuestionFormDTO questionDTO) {

        interactionQuestionService.addInteractionQuestion(questionDTO);
    }

    @GetMapping("page")
    @ApiOperation("分页查询互动问题")
    public PageDTO<QuestionVO>queryQuestionPage(QuestionPageQuery query){
        return interactionQuestionService.queryQuestionPage(query);
    }

    @GetMapping("{id}")
    @ApiOperation("根据id查询互动问题")
    public QuestionVO queryQuestionById(@PathVariable("id") Long id) {
        return interactionQuestionService.queryQuestionById(id);
    }
    @DeleteMapping("{id}")
    @ApiOperation("删除互动问题")
    public void deleteQuestion(@PathVariable("id") Long id) {
        interactionQuestionService.deleteQuestion(id);
    }
    @PutMapping("{id}")
    @ApiOperation("修改互动问题")
    public void updateQuestion(@Valid@PathVariable("id") Long id,
    @RequestBody QuestionFormDTO questionDTO) {
        interactionQuestionService.updateQuestion(id,questionDTO);
    }


}
